class Solution:
    def singleNumber(self, nums: List[int]) -> int:
        nums = sorted(nums)
        n = len(nums)
        i = 0
        while i < n - 1:
            if not nums[i] == nums[i + 1]:
                return nums[i]
            i += 2
        return nums[n - 1] # 返回最后一个或第一个数字
# 方法二
class Solution:
    def singleNumber(self, nums: List[int]) -> int:
        return reduce(xor, nums)# 异或运算